package com.etang.guosaia20201004;

import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.bizideal.smarthome.socket.ConstantUtil;
import com.bizideal.smarthome.socket.ControlUtils;
import com.bizideal.smarthome.socket.DataCallback;
import com.bizideal.smarthome.socket.DeviceBean;
import com.bizideal.smarthome.socket.LoginCallback;
import com.bizideal.smarthome.socket.SocketClient;
import com.etang.guosaia20201004.tools.DiyToast;
import com.etang.guosaia20201004.tools.MyDataBaseHelper;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

public class IndexActivity extends AppCompatActivity {


    private ImageView iv_temp, iv_hum;
    private float temp, hum, ill, smo, gas, press, per, co, pm;
    private TextView tv_temp, tv_hum, tv_ill, tv_smo, tv_gas, tv_press, tv_per, tv_co, tv_pm;
    private Handler handler;
    private Runnable timeRunnable;
    private Handler handler2;
    private Runnable timeRunnable2;
    private CheckBox cb_lamp1, cb_lamp2, cb_warm, cb_fan, cb_door, cb_dvd, cb_kt, cb_tv, cb_cur;
    private MyDataBaseHelper dbHelper;
    private SQLiteDatabase db;
    private ListView lv_data, lv_link_data;
    private Spinner sp_data;
    private SharedPreferences sharedPreferences;
    private List<String> list = new ArrayList<String>();
    private int number = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);
        initView();
        initWeb();
        start_thread();
        start_thread_2();
        cb_door.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    ControlUtils.control(ConstantUtil.RFID_Open_Door, ConstantUtil.CHANNEL_1, ConstantUtil.OPEN);
                }
            }
        });
        cb_warm.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    ControlUtils.control(ConstantUtil.WarningLight, ConstantUtil.CHANNEL_ALL, ConstantUtil.OPEN);
                } else {
                    ControlUtils.control(ConstantUtil.WarningLight, ConstantUtil.CHANNEL_ALL, ConstantUtil.CLOSE);
                }
            }
        });
        cb_fan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    ControlUtils.control(ConstantUtil.Fan, ConstantUtil.CHANNEL_ALL, ConstantUtil.OPEN);
                } else {
                    ControlUtils.control(ConstantUtil.Fan, ConstantUtil.CHANNEL_ALL, ConstantUtil.CLOSE);
                }
            }
        });
        cb_cur.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    ControlUtils.control(ConstantUtil.Curtain, ConstantUtil.CHANNEL_1, ConstantUtil.OPEN);
                } else {
                    ControlUtils.control(ConstantUtil.Curtain, ConstantUtil.CHANNEL_2, ConstantUtil.CLOSE);
                }
            }
        });
        cb_lamp2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    ControlUtils.control(ConstantUtil.Lamp, ConstantUtil.CHANNEL_2, ConstantUtil.OPEN);
                } else {
                    ControlUtils.control(ConstantUtil.Lamp, ConstantUtil.CHANNEL_2, ConstantUtil.CLOSE);
                }
            }
        });
        cb_lamp1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    ControlUtils.control(ConstantUtil.Lamp, ConstantUtil.CHANNEL_1, ConstantUtil.OPEN);
                } else {
                    ControlUtils.control(ConstantUtil.Lamp, ConstantUtil.CHANNEL_1, ConstantUtil.CLOSE);
                }
            }
        });
        cb_tv.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    ControlUtils.control(ConstantUtil.INFRARED_1_SERVE, "1", ConstantUtil.OPEN);
                } else {
                    ControlUtils.control(ConstantUtil.INFRARED_1_SERVE, "1", ConstantUtil.OPEN);
                }
            }
        });
        cb_kt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    ControlUtils.control(ConstantUtil.INFRARED_1_SERVE, "2", ConstantUtil.OPEN);
                } else {
                    ControlUtils.control(ConstantUtil.INFRARED_1_SERVE, "2", ConstantUtil.OPEN);
                }
            }
        });
        cb_dvd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    ControlUtils.control(ConstantUtil.INFRARED_1_SERVE, "3", ConstantUtil.OPEN);
                } else {
                    ControlUtils.control(ConstantUtil.INFRARED_1_SERVE, "3", ConstantUtil.OPEN);
                }
            }
        });
    }

    private void initData() {
        ControlUtils.getData();
        SocketClient.getInstance().getData(new DataCallback<DeviceBean>() {

            @Override
            public void onResult(final DeviceBean getdata) {
                // TODO Auto-generated method stub
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        if (!TextUtils.isEmpty(getdata.getAirPressure())) {
                            tv_press.setText("气压：" + getdata.getAirPressure());
                            press = Float.valueOf(getdata.getAirPressure());
                        }
                        if (!TextUtils.isEmpty(getdata.getCo2())) {
                            tv_co.setText("Co2：" + getdata.getCo2());
                            co = Float.valueOf(getdata.getCo2());
                        }
                        if (!TextUtils.isEmpty(getdata.getGas())) {
                            tv_gas.setText("燃气：" + getdata.getGas());
                            gas = Float.valueOf(getdata.getGas());
                        }
                        if (!TextUtils.isEmpty(getdata.getHumidity())) {
                            tv_hum.setText("湿度：" + getdata.getHumidity());
                            hum = Float.valueOf(getdata.getHumidity());
                            iv_hum.setRotation(hum);
                        }
                        if (!TextUtils.isEmpty(getdata.getIllumination())) {
                            tv_ill.setText("光照：" + getdata.getIllumination());
                            ill = Float.valueOf(getdata.getIllumination());
                        }
                        if (!TextUtils.isEmpty(getdata.getPM25())) {
                            tv_pm.setText("PM2.5：" + getdata.getPM25());
                            pm = Float.valueOf(getdata.getPM25());
                        }
                        if (!TextUtils.isEmpty(getdata.getSmoke())) {
                            tv_smo.setText("烟雾：" + getdata.getSmoke());
                            smo = Float.valueOf(getdata.getSmoke());
                        }
                        if (!TextUtils.isEmpty(getdata.getTemperature())) {
                            tv_temp.setText("温度：" + getdata.getTemperature());
                            temp = Float.valueOf(getdata.getTemperature());
                            iv_temp.setRotation(temp);
                        }
                        if (!TextUtils.isEmpty(getdata.getStateHumanInfrared())) {
                            per = Float.valueOf(getdata.getTemperature());
                            if (per == 1) {
                                tv_per.setText("人体红外：有人");
                            } else {
                                tv_per.setText("人体红外：无人");
                            }
                        }
                    }
                });
            }
        });
    }

    private void initWeb() {
        ControlUtils.setUser("bizideal", "123456", SocketClient.ip);
        SocketClient.getInstance().creatConnect();
        SocketClient.getInstance().login(new LoginCallback() {
            @Override
            public void onEvent(final String web) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (web.equals(ConstantUtil.SUCCESS)) {
                            DiyToast.showToast(getApplicationContext(), "网络连接成功");
                            initData();
                        } else {
                            DiyToast.showToast(getApplicationContext(), "网络连接失败");
                            initData();
                        }
                    }
                });
            }
        });
    }

    private void setdata() {
        Cursor cursor = db.rawQuery("SELECT * FROM DATA WHERE DATA_NAME = ?", new String[]{sp_data.getSelectedItem().toString()});
        if (cursor.getCount() != 0) {
            cursor.moveToFirst();
            SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(IndexActivity.this, R.layout.layout_item, cursor, new String[]{"DATA_NAME", "DATA_NUMBER", "TIME"}, new int[]{R.id.tv_item_value, R.id.tv_item_data, R.id.tv_item_time}, 1);
            lv_data.setAdapter(simpleCursorAdapter);
        }
    }

    private void check_smo() {
        String state = sharedPreferences.getString("smo_state", null);
        list.add("监测烟雾--" + state);
    }

    private void check_temp() {
        String state = sharedPreferences.getString("temp_state", null);
        list.add("监测温度--" + state);
    }

    private void check_co2() {
        String state = sharedPreferences.getString("co_state", null);
        list.add("监测CO2--" + state);
    }

    private void check_ill() {
        String state = sharedPreferences.getString("ill_state", null);
        list.add("监测光照--" + state);
    }

    private void check_per() {
        String state = sharedPreferences.getString("per_state", null);
        list.add("绿色模式--" + state);
    }

    public void user_setting(View view) {

    }

    public void values_setting(View view) {
        AlertDialog.Builder builder = new AlertDialog.Builder(IndexActivity.this);
        builder.setTitle("阈值管理");
        View view1 = LayoutInflater.from(IndexActivity.this).inflate(R.layout.dialog_values, null, false);
        builder.setView(view1);
        final CheckBox cb_temp, cb_co, cb_ill, cb_smo, cb_per;
        cb_co = (CheckBox) view1.findViewById(R.id.cb_co);
        cb_ill = (CheckBox) view1.findViewById(R.id.cb_ill);
        cb_per = (CheckBox) view1.findViewById(R.id.cb_per);
        cb_smo = (CheckBox) view1.findViewById(R.id.cb_smo);
        cb_temp = (CheckBox) view1.findViewById(R.id.cb_temp);
        final EditText et_smo, et_temp_max, et_temp_low, et_ill_max, et_ill_low, et_co_max, et_co_low, et_per;
        et_ill_low = (EditText) view1.findViewById(R.id.et_ill_values_low);
        et_ill_max = (EditText) view1.findViewById(R.id.et_ill_values_max);
        et_per = (EditText) view1.findViewById(R.id.et_per_values);
        et_smo = (EditText) view1.findViewById(R.id.et_smo_values);
        et_temp_low = (EditText) view1.findViewById(R.id.et_temp_values_low);
        et_temp_max = (EditText) view1.findViewById(R.id.et_temp_values_max);
        et_co_low = (EditText) view1.findViewById(R.id.et_co_values_low);
        et_co_max = (EditText) view1.findViewById(R.id.et_co_values_max);
        et_co_low.setText(sharedPreferences.getString("co_low_values", null));
        et_co_max.setText(sharedPreferences.getString("co_max_values", null));
        et_ill_low.setText(sharedPreferences.getString("ill_low_values", null));
        et_ill_max.setText(sharedPreferences.getString("ill_max_values", null));
        et_per.setText(sharedPreferences.getString("per_values", null));
        et_smo.setText(sharedPreferences.getString("smo_values", null));
        et_temp_low.setText(sharedPreferences.getString("temp_low_values", null));
        et_temp_max.setText(sharedPreferences.getString("temp_max_values", null));
        if (sharedPreferences.getString("co_state", null).equals("开")) {
            cb_co.setChecked(true);
        }
        if (sharedPreferences.getString("ill_state", null).equals("开")) {
            cb_ill.setChecked(true);
        }
        if (sharedPreferences.getString("smo_state", null).equals("开")) {
            cb_smo.setChecked(true);
        }
        if (sharedPreferences.getString("per_state", null).equals("开")) {
            cb_per.setChecked(true);
        }
        if (sharedPreferences.getString("temp_state", null).equals("开")) {
            cb_temp.setChecked(true);
        }
        cb_co.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sharedPreferences.edit().putString("co_state", "开").commit();
                } else {
                    sharedPreferences.edit().putString("co_state", "关").commit();
                }
            }
        });
        cb_per.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sharedPreferences.edit().putString("per_state", "开").commit();
                } else {
                    sharedPreferences.edit().putString("per_state", "关").commit();
                }
            }
        });
        cb_smo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sharedPreferences.edit().putString("smo_state", "开").commit();
                } else {
                    sharedPreferences.edit().putString("smo_state", "关").commit();
                }
            }
        });
        cb_temp.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sharedPreferences.edit().putString("temp_state", "开").commit();
                } else {
                    sharedPreferences.edit().putString("temp_state", "关").commit();
                }
            }
        });
        cb_ill.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sharedPreferences.edit().putString("ill_state", "开").commit();
                } else {
                    sharedPreferences.edit().putString("ill_state", "关").commit();
                }
            }
        });
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (et_co_low.getText().toString().isEmpty()
                        || et_co_max.getText().toString().isEmpty()
                        || et_ill_low.getText().toString().isEmpty()
                        || et_ill_max.getText().toString().isEmpty()
                        || et_per.getText().toString().isEmpty()
                        || et_smo.getText().toString().isEmpty()
                        || et_temp_low.getText().toString().isEmpty()
                        || et_temp_max.getText().toString().isEmpty()) {
                    DiyToast.showToast(IndexActivity.this, "请不要有空白项");
                } else {
                    sharedPreferences.edit().putString("per_values", et_per.getText().toString()).commit();
                    sharedPreferences.edit().putString("smo_values", et_smo.getText().toString()).commit();
                    sharedPreferences.edit().putString("co_low_values", et_co_low.getText().toString()).commit();
                    sharedPreferences.edit().putString("co_max_values", et_co_max.getText().toString()).commit();
                    sharedPreferences.edit().putString("ill_low_values", et_ill_low.getText().toString()).commit();
                    sharedPreferences.edit().putString("ill_max_values", et_ill_max.getText().toString()).commit();
                    sharedPreferences.edit().putString("temp_low_values", et_temp_low.getText().toString()).commit();
                    sharedPreferences.edit().putString("temp_max_values", et_temp_max.getText().toString()).commit();
                }
            }
        });
        builder.show();
    }


    private void start_thread_2() {
        handler2 = new Handler() {
            @Override
            public void handleMessage(@NonNull Message msg) {
                super.handleMessage(msg);
                list.clear();
                check_temp();
                check_ill();
                check_smo();
                check_per();
                check_co2();
                ListAdapter mAdapter = new ArrayAdapter<String>(IndexActivity.this,
                        android.R.layout.simple_list_item_1, list);
                lv_link_data.setAdapter(mAdapter);
                if (sharedPreferences.getString("smo_state", null).equals("开")) {
                    if (smo > Integer.valueOf(sharedPreferences.getString("smo_values", null))) {
                        ControlUtils.control(ConstantUtil.Fan, ConstantUtil.CHANNEL_ALL, ConstantUtil.OPEN);
                        ControlUtils.control(ConstantUtil.WarningLight, ConstantUtil.CHANNEL_ALL, ConstantUtil.OPEN);
                    }
                }
                if (sharedPreferences.getString("ill_state", null).equals("开")) {
                    if (ill > Integer.valueOf(sharedPreferences.getString("ill_max_values", null))) {
                        ControlUtils.control(ConstantUtil.Lamp, ConstantUtil.CHANNEL_ALL, ConstantUtil.CLOSE);
                    }
                    if (ill < Integer.valueOf(sharedPreferences.getString("ill_low_values", null))) {
                        ControlUtils.control(ConstantUtil.Lamp, ConstantUtil.CHANNEL_ALL, ConstantUtil.OPEN);
                    }
                }
                if (sharedPreferences.getString("temp_state", null).equals("开")) {
                    if (temp > Integer.valueOf(sharedPreferences.getString("temp_max_values", null))) {
                        ControlUtils.control(ConstantUtil.INFRARED_1_SERVE, "1", ConstantUtil.OPEN);
                    }
                    if (temp < Integer.valueOf(sharedPreferences.getString("temp_low_values", null))) {
                        ControlUtils.control(ConstantUtil.INFRARED_1_SERVE, "1", ConstantUtil.OPEN);
                    }
                }
                if (sharedPreferences.getString("co_state", null).equals("开")) {
                    if (co > Integer.valueOf(sharedPreferences.getString("co_max_values", null))) {
                        ControlUtils.control(ConstantUtil.Fan, ConstantUtil.CHANNEL_ALL, ConstantUtil.OPEN);
                    }
                    if (co < Integer.valueOf(sharedPreferences.getString("co_low_values", null))) {
                        ControlUtils.control(ConstantUtil.Fan, ConstantUtil.CHANNEL_ALL, ConstantUtil.CLOSE);
                    }

                }
                if (sharedPreferences.getString("per_state", null).equals("开")) {
                    if (per == 1) {
                        number = 0;
                    } else {
                        number++;
                        if (number == 5000) {
                            DiyToast.showToast(getApplicationContext(), "进入绿色模式");
                            sharedPreferences.edit().putString("smo_state", "关").commit();
                            sharedPreferences.edit().putString("ill_state", "关").commit();
                            sharedPreferences.edit().putString("temp_state", "关").commit();
                            sharedPreferences.edit().putString("co_state", "关").commit();
                        }
                    }
                }
                handler2.postDelayed(timeRunnable2, 1000);
            }
        };
        timeRunnable2 = new Runnable() {
            @Override
            public void run() {
                Message msg = handler2.obtainMessage();
                handler2.sendMessage(msg);
            }
        };
        handler2.post(timeRunnable2);
    }

    private void start_thread() {
        handler = new Handler() {
            @Override
            public void handleMessage(@NonNull Message msg) {
                super.handleMessage(msg);
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
                String time = simpleDateFormat.format(new Date());
                db.execSQL("INSERT INTO DATA (DATA_NAME,DATA_NUMBER,TIME)VALUES(?,?,?)", new String[]{"气压", String.valueOf(press), time});
                db.execSQL("INSERT INTO DATA (DATA_NAME,DATA_NUMBER,TIME)VALUES(?,?,?)", new String[]{"CO2", String.valueOf(co), time});
                db.execSQL("INSERT INTO DATA (DATA_NAME,DATA_NUMBER,TIME)VALUES(?,?,?)", new String[]{"燃气", String.valueOf(gas), time});
                db.execSQL("INSERT INTO DATA (DATA_NAME,DATA_NUMBER,TIME)VALUES(?,?,?)", new String[]{"湿度", String.valueOf(hum), time});
                db.execSQL("INSERT INTO DATA (DATA_NAME,DATA_NUMBER,TIME)VALUES(?,?,?)", new String[]{"光照", String.valueOf(ill), time});
                db.execSQL("INSERT INTO DATA (DATA_NAME,DATA_NUMBER,TIME)VALUES(?,?,?)", new String[]{"PM2.5", String.valueOf(pm), time});
                db.execSQL("INSERT INTO DATA (DATA_NAME,DATA_NUMBER,TIME)VALUES(?,?,?)", new String[]{"烟雾", String.valueOf(smo), time});
                db.execSQL("INSERT INTO DATA (DATA_NAME,DATA_NUMBER,TIME)VALUES(?,?,?)", new String[]{"温度", String.valueOf(temp), time});
                db.execSQL("INSERT INTO DATA (DATA_NAME,DATA_NUMBER,TIME)VALUES(?,?,?)", new String[]{"人体红外", String.valueOf(per), time});
                setdata();
                handler.postDelayed(timeRunnable, 5000);
            }
        };
        timeRunnable = new Runnable() {
            @Override
            public void run() {
                Message msg = handler.obtainMessage();
                handler.sendMessage(msg);
            }
        };
        handler.post(timeRunnable);
    }

    private void initView() {
        sharedPreferences = getSharedPreferences("rember", MODE_PRIVATE);
        dbHelper = new MyDataBaseHelper(getApplicationContext(), "info.db", null, 2);
        db = dbHelper.getWritableDatabase();
        lv_link_data = (ListView) findViewById(R.id.lv_link_state);
        sp_data = (Spinner) findViewById(R.id.sp_chose_data);
        lv_data = (ListView) findViewById(R.id.lv_data);
        cb_cur = (CheckBox) findViewById(R.id.cb_cur);
        cb_door = (CheckBox) findViewById(R.id.cb_door);
        cb_dvd = (CheckBox) findViewById(R.id.cb_dvd);
        cb_fan = (CheckBox) findViewById(R.id.cb_fan);
        cb_kt = (CheckBox) findViewById(R.id.cb_kt);
        cb_lamp1 = (CheckBox) findViewById(R.id.cb_lamp1);
        cb_lamp2 = (CheckBox) findViewById(R.id.cb_lamp2);
        cb_tv = (CheckBox) findViewById(R.id.cb_tv);
        cb_warm = (CheckBox) findViewById(R.id.cb_warm);
        iv_hum = (ImageView) findViewById(R.id.iv_hum);
        iv_temp = (ImageView) findViewById(R.id.iv_temp);
        tv_hum = (TextView) findViewById(R.id.tv_hum);
        tv_temp = (TextView) findViewById(R.id.tv_temp);
        tv_co = (TextView) findViewById(R.id.tv_co);
        tv_gas = (TextView) findViewById(R.id.tv_gas);
        tv_ill = (TextView) findViewById(R.id.tv_ill);
        tv_per = (TextView) findViewById(R.id.tv_per);
        tv_pm = (TextView) findViewById(R.id.tv_pm);
        tv_press = (TextView) findViewById(R.id.tv_press);
        tv_smo = (TextView) findViewById(R.id.tv_smo);
    }
}